﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="assets/css/layui.css">
    <link rel="stylesheet" href="assets/css/login.css">
    <link rel="icon" href="/favicon.ico">
    <title>快递e栈管理后台</title>
</head>
<body class="login-wrap">
    <div class="login-container">
    	<h3>快递e栈后台管理</h3>
        <form class="login-form" action="index.html">
            <div class="input-group">
                <input type="text" id="username" name="username" class="input-field">
                <label for="username" class="input-label">
                    <span id="yonghu" class="label-title">用户名</span>
                </label>
            </div>
            <div class="input-group">
                <input type="password" id="password" name="password" class="input-field">
                <label for="password" class="input-label">
                    <span id="mima" class="label-title">密码</span>
                </label>
            </div>
            <button type="button" id="denglu" class="login-button">登录<i class="ai ai-enter"></i></button>
        </form>
    </div>
</body>
<script src="assets/layui.js"></script>
<script src="js/index.js" data-main="login"></script>
<script src="js/login.js" data-main="login"></script>
<script src="../qrcode/jquery2.1.4.js"></script>
<script src="../layer/layer.js"></script>



<script>
    function sureName(){
        var name=$("input[name='username']").val();
        if(name==""){
            $("span[id='yonghu']").html("*用户名不能为空！").css("color","tomato");
            return false;
        }else if(name.length<2||name.length>8){
            $("span[id='yonghu']").html("*用户名长度只能2~8位").css('color','tomato');
            return false;
        }
        $("span[id='yonghu']").html("用户名").css("color","black");
        return true;
    }
    function surePassword(){
        var val=$("input[name='password']").val();
        if(val==""){
            $("span[id='mima']").html("*密码不能为空！").css("color","tomato");
            return false;
        }else if(val.length<6){
            $("span[id='mima']").html("*密码长度至少6位！").css("color","tomato");
            return false;
        }
        $("span[id='mima']").html("密码").css("color","black");
        return true;
    }


    $(function(){


            $("input[name='username']").blur(function(){
                sureName();
            });
            $("input[name='password']").blur(function(){
                surePassword();
            });

            $("button[id='denglu']").click(function(){
                var rs = sureName()&&surePassword();
                if (rs){             //如果点击登录的时候，用户名和密码输入都没问题就返回true
                    var username = $("#username").val();
                    var password = $("#password").val();
                    //1.  先使用layer，弹出load（提示加载中）
                    var windowId = layer.load();
                    //2.    ajax与服务器交互
                    $.post("login.do",{username:username,password:password},function (data) {
                        //3、    关闭load窗口
                        layer.close(windowId);
                        //4、    将服务器回复的结果进行显示
                        layer.msg(data.result);
                        if (data.status==0){
                            //跳转主页
                            location.assign("index.html")
                        }

                    })
                }
            });



    });
</script>
</html>